{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    {include file='public:left-menu'/}
    <!--End 左侧导航-->
    <!--头部信息-->
    {include file='public:nav-header' title="会员管理" subTitle="添加编辑团队等级"/}
    <!--End 头部信息-->

    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                <form method="post" id="submit-form" class="row">
                  <div class="form-group col-md-12">
                    <div class="row">
                      <div class="col-md-3">
                        <label class="form-title"><em class="require">*</em>等级名称</label>
                        <input type="text" class="form-control" name="name" value="{$level.name}" placeholder="请输入等级名称"/>
                        <span class="help">等级必要名称</span>
                        <span class="error" id="err_name"></span>
                      </div>
                      <div class="col-md-3">
                        <label class="form-title"><em class="require">*</em>业绩要求</label>
                        <input type="text" class="form-control" name="yeji" value="{$level.yeji}" placeholder="请输入业绩要求"/>
                        <span class="help">升级该级别要求业绩多少盒</span>
                        <span class="error" id="err_yeji"></span>
                      </div>
                      <div class="col-md-3">
                        <label class="form-title"><em class="require">*</em>级差奖励比例</label>
                        <input type="text" class="form-control" name="jl_bl" value="{$level.jl_bl}" placeholder="请输入级差奖励比例"/>
                        <span class="help">升级该级别级差奖励 单位为%</span>
                        <span class="error" id="err_jl_bl"></span>
                      </div>
                      <div class="col-md-3">
                        <label class="form-title"><em class="require">*</em>平级奖励比例</label>
                        <input type="text" class="form-control" name="pj_bl" value="{$level.pj_bl}" placeholder="请输入平级奖励比例"/>
                        <span class="help">升级该级别平级奖励比例 单位为%</span>
                        <span class="error" id="err_pj_bl"></span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group col-md-12">
                    <div class="row">
                      <div class="col-md-9">
                        <label class="form-title"><em class="require">*</em>升级条件</label>
                        <div class="form-inline">
                          <span>小区业绩&nbsp;</span>
                          <input type="text" class="form-control" name="xq_yeji" value="{$level.xq_yeji}" placeholder="请输入小区业绩"/>
                          <span>&nbsp;盒&nbsp;并培养&nbsp;</span>
                          <input type="number" class="form-control" name="num" value="{$level.num}" placeholder="请输入数量"/>
                          <span>&nbsp;名&nbsp;</span>
                          <select class="input-group-select" name="num_level_id">
                            <option value="">无</option>
                            {volist name="$level_list" id="level1"}
                            <option value="{$level1.level_id}" {if $level.num_level_id==$level1.level_id}selected{/if}>{$level1.name}</option>
                            {/volist}
                          </select>
                        </div>
                        <span class="error" id="err_xq_yeji"></span>
                        <span class="error" id="err_num"></span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group col-md-12">
                    <input type="hidden" name="{$level.pk}" value="{$level[$level.pk]}">
                    <button type="button" class="btn-theme submit-btn">确定</button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript">
  $(function(){
    $('.submit-btn').click(function () {
      $('span.error').hide();
      $('span.error').parent().removeClass('has-error');
      var url = "{:url('User/add_edit_td_level')}";
      var data = $('#submit-form').serialize();
      $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: 'json',
        success: function (data) {
          if (data.code == 1) {
            showSuccessMsg(data.msg, function () {
              if (data.url) {
                location.href = data.url;
              }
            });
          } else if (data.code == 10) {
              showErrorMsg(data.msg);
            $.each(data.data.result, function(index, item) {
              $('#err_' + index).text(item).show();
              $('#err_' + index).parent().addClass('has-error');
            });
          } else {
              showErrorMsg(data.msg);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            showErrorMsg("网络失败，请刷新后重试!");
        }
      });
    });
  });
  function call_back(fileurl_tmp,fileurl_id)
  {
    $("[name="+fileurl_id+"]").val(fileurl_tmp);
    $("#"+fileurl_id).attr('src', fileurl_tmp);
  }
</script>
</body>
</html>
